//
//  XHComposeTextView.swift
//  gu-新浪微博
//
//  Created by xiaohui on 16/7/3.
//  Copyright © 2016年 gusheghui. All rights reserved.
//

import UIKit

class XHComposeTextView: UITextView {

    var placeholderStr: String?{
        didSet{
            placeholderLabel.text = placeholderStr
        }
    }
    
    
    override var font: UIFont?{
     
        didSet{
            placeholderLabel.font = font
        }
    }
    
    
    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        setupUi()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setupUi(){
//        print("1")
        backgroundColor = RandomColor()
        addSubview(placeholderLabel)
        placeholderLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self).offset(8)
            make.left.equalTo(self).offset(5)
            make.width.equalTo(SCREENW - 10)
        }
        
        //发送通知
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "textDidChange", name: UITextViewTextDidChangeNotification, object: nil)
        
        
        
    }
    // 监听通知 textView 输入文字的时候调用
    func textDidChange(){
            placeholderLabel.hidden = self.hasText()
    }
    //移除通知
    deinit{
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
    private lazy var placeholderLabel : UILabel = {
       
        let lable = UILabel()
        
        lable.textColor = UIColor.whiteColor()
        lable.numberOfLines = 0
        
        return lable
    }()
    
    private lazy var pictruView:XHComposePictureView = XHComposePictureView()
    
}
